package com.xzy.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
    public static int getWeek() throws Exception {
        Date date=new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String nowTime=sdf.format(date);
        Date time=sdf.parse(nowTime);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(time);
        int week = calendar.get(Calendar.WEEK_OF_MONTH);
        return week;
    }
    public static int getMonth() throws Exception {
        Date date=new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String nowTime=sdf.format(date);
        Date time=sdf.parse(nowTime);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(time);
        int month = calendar.get(Calendar.MONTH)+1;
        return month;
    }
    public static int getYear() throws Exception {
        Date date=new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String nowTime=sdf.format(date);
        Date time=sdf.parse(nowTime);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(time);
        int year = calendar.get(Calendar.YEAR);
        return year;
    }
}